<template>
	<view class="content">
		<view class="login_from">

			<view class="login_from_input">
				<view class="login_from_name">手机号</view>
				<view class="login_from_fun"><input @input="inputData" v-model="phone" focus type="text" placeholder="请输入手机号码(11位)"></view>
				<!-- 使用数据绑定获取输入框的值 -->
			</view>

			<view class="login_from_input">
				<view class="login_from_name">验证码</view>
				<view class="login_from_fun"><input type="digit" @input="inputpass" v-model="password"  placeholder="请输入验证码(6位)"></view>
				<view class="yanzheng" @click="handerclick">获取验证码</view>
			</view>


			<view class="login_from_dl">
				<button @click="denglu">登录</button>
			</view>
		</view>

	</view>
</template>
<script>
	import axios from "axios"
	import {mapState,mapMutations}from 'vuex'
	export default {
		data() {
			return {
				phone:null,
				password:null,
				phonechoice:false,
				passwordchoice:false,
			}
		},
		
		onLoad() {
			
		},
		mounted() {
			
		},
		methods: { 
			...mapMutations(['login']),  //使用辅助函数获取同步方法
				handerclick(){              
					uni.showToast({
						title:'输入六位数字(-随便输-)',
						duration:1000,
						icon:'none'
					})
				},
				inputData(e){
					this.phone = e.detail.value    //读取到phone数据进行赋值
				},
				inputpass(e){
					this.password = e.detail.value     //读取到password数据进行赋值
				},


			denglu() {
				var phonereg =/^1[3-9]{1}[0-9]{9}$/    //使用正则表达式进行判断是否符合条件，
				var passwordreg =/^\d{6}$/
				if(phonereg.test( this.phone )){
					this.phonechoice = true
				}else{
					uni.showToast({
						title:'请输入正确的11位手机号',
						duration:1000,
						icon:'none'
					})
				}
				if(passwordreg.test( this.password )){
					this.passwordchoice = true
				}else{
					uni.showToast({
						title:'请输入正确的6位验证码',
						duration:1000,
						icon:'none'
					})
				}
				if(this.phonechoice == true  && this.passwordchoice ==true ){
					this.login(this.phone)									//使用vuex同步方法存储数据
					uni.switchTab({
						url:"/pages/tabbar/index/index"						//条件成立跳转页面
					})
				}
			}
		}
	}
</script>
<style lang="scss" scoped>

	.login_img {
		width: 100%;
		height: auto;
		margin-top: 90upx;
	}

	.login_img image {
		width: 200upx;
		height: 200upx;
		display: block;
		margin: 0px auto;
		border-radius: 50%;
	}

	.login_from {
		width: 100%;
		height: auto;
		box-sizing: border-box;
		padding: 40upx 8%;
		margin-top: 80upx;
	}

	.login_from_input {
		width: 100%;
		height: auto;
		display: flex;
		flex-direction: row;
		justify-content: space-between;
		align-items: center;
		border-bottom: 1px #eee solid;
		padding: 50upx 0px;
		margin: 0px auto;
		position: relative;
		.yanzheng{
			width: 90px;
			height: 30px;
			position: absolute;
			right:20rpx;
			border-radius: 25px;
			background-color: rgb(8,175,254);
			text-align: center;
			line-height: 30px;
			color: white;
			font-size: 15px;
		}
	}

	.login_from_name {
		width: 20%;
	}

	.login_from_fun {
		width: 80%;
		display: flex;
		flex-direction: row;
		justify-content: flex-end;
	}

	.login_from_fun input {
		width: 100%;
		text-align: left;
		font-size: 14px;
	}


	.login_from_dl {
		width: 100%;
		height: 50px;
		line-height: 50px;
		margin-top: 150upx;
		border-radius: 25px;
		overflow: hidden;
	}

	.login_from_dl button {
		width: 100%;
		height: 50px;
		line-height: 50px;
		background: rgb(8,175,254);
		color: #fff;
		border-radius: 0px;
	}

	.logo_xieyi {
		width: 100%;
		height: 40px;
		line-height: 40px;
		display: flex;
		flex-direction: row;
		margin-top: 30upx;
		align-items: center;
		color: #444;
		font-size: 14px;
		justify-content: center;
	}

	.logo_xieyi label {
		font-size: 18px;
		margin-right: 1%;
		display: block;
		width: 15px;
		height: 15px;
	}

	.cuIcon-squarecheckfill {
		color: #007AFF;
	}

	.logo_text text {
		color: #007AFF;
	}

	.cuIcon-squarecheckfill {
		background: #007AFF;
		position: relative;
		border: 2px #ccc solid;
		box-sizing: border-box;
		border-radius: 3px;
	}

	.cuIcon-square {
		background: #fff;
		border: 2px #ccc solid;
		box-sizing: border-box;
		border-radius: 3px;
	}
</style>
